package org.roger.analyzer;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.core.LowerCaseFilter;
import org.apache.lucene.analysis.core.StopFilter;
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.apache.lucene.analysis.util.CharArraySet;
import org.roger.index.filter.PayloadsFilter;
import org.roger.index.filter.SplitSpotFilter;

/**
 * 停用词和句号分割解析器
 * @author luoweiyi
 */
public class SplitSpotAnalyzer extends Analyzer{
	
	private CharArraySet stopWords;
	
	public SplitSpotAnalyzer(CharArraySet stopWords){
		this.stopWords = stopWords;
	}

	@Override
	protected TokenStreamComponents createComponents(String fieldName) {
		final StandardTokenizer src = new StandardTokenizer();
		
		TokenStream tok = new LowerCaseFilter(src);
		tok = new StopFilter(tok,stopWords);
		tok = new SplitSpotFilter(tok);
		tok = new PayloadsFilter(tok,5f);
		
	    return new TokenStreamComponents(src, tok);
	}

}
